import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import direct_to from '@dfeidao/atom-web/url/direct-to';
import P05 from './P05';
export default async function a006(fd: IFeidaoAiBrowserComponent, e: Event) {
	// todo
	// 点击内容
	// console.log('点击消息内容');
	const target = e.currentTarget as HTMLDivElement;
	const msgid = target.getAttribute('fd-value');
	const msg_page_url = target.getAttribute('fd-value1');
	const msg_cont = target.getAttribute('fd-value2');
	// console.log(msgid);
	// console.log(msg_page_url);
	// console.log(msg_cont);
	const productid = get(fd, 'productid');
	const staff_no = get(fd, 'staff_no');
	const query = {
		productid,
		msgid,
		staff_no
	};
	if (msg_page_url) {
		const data = await nodejs<{ res: Array<{ param_name: string, param_datatype: string, param_value: string }> }>('common/zjc-000001/s005', query);
		// console.log('data.res:');
		// console.log(data.res);
		if (data.res.length > 0) {
			const name = data.res[0].param_name as string;
			const value = data.res[0].param_value;
			direct_to(msg_page_url, { [name]: value }, true);
			const res = await nodejs<{ code: number }>('common/zjc-000001/s006', query);
			console.log(res, 'zjc-000001', 'a004');
			fire('zjc-000001', 'a004');
			// await a001(fd);
		} else {
			const mgxq = fd.data.node.querySelector<HTMLDivElement>('[mgxq]');
			set_node_cls(mgxq, 'display-n', false);
			const qwe = [{ msg_cont }];
			render(fd, qwe, P05, 'P05', 'inner');
			await nodejs<{ code: number }>('common/zjc-000001/s006', query);
			// console.log(res1, 'zjc-000006', 'a001');
		}
	} else {
		// fire('zjc-000006', 'a001', msg_cont);
		const mgxq = fd.data.node.querySelector<HTMLDivElement>('[mgxq]');
		set_node_cls(mgxq, 'display-n', false);
		const qwe = [{ msg_cont }];
		render(fd, qwe, P05, 'P05', 'inner');
		await nodejs<{ code: number }>('common/zjc-000001/s006', query);
		// console.log(res1, 'zjc-000006', 'a00111s', msg_cont);
	}
}
